<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>支付宝二维码付款</title>
    <link rel="StyleSheet" href="../css/common.css" type="text/css" media="screen" />
    <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
    <script src="https://cdn.staticfile.org/qrcodejs/1.0.0/qrcode.min.js"></script>
</head>
<body>
<div th:replace="common/top"></div>
<!--<div id="Orcode_div" style="height: 165px;width: 165px"></div>-->
<div id="w">
    <div id="content-center">
        <div id="qrcode"></div>
    </div>
    <div id="link_center">
        <a class="payLinkItem" id="finishPay" href="/user/finishPay" type="button">完成支付</a>
        <a class="payLinkItem" href="/user/cancelPay" type="button">取消支付</a>
    </div>
</div>

<div th:replace="common/bottom"></div>
</body>
</html>
<script type="application/javascript" th:inline="javascript">
    $(function (){
    //项目名称
    // var basePath="/byyu";
    //商户订单编号
    // var outTradeNo;
    var url = [[${qrCode}]];
    console.log(url);
    createQrcode1(url);
    function createQrcode1(url) {
        var qrcode = new QRCode(document.getElementById("qrcode"), {
            text: url,
            width: 168, //宽度
            height: 168, //高度
            // colorDark: "#000000",
            // colorLight: "#ffffff",
            // correctLevel: QRCode.CorrectLevel.H
        });
        qrcode.makeCode(url);
    }
    //预下单
    $('#finishPay').click(function (event){
        event.preventDefault();

        var outTradeNo = [[${outTradeNo}]];
        $.ajax({
            url: 'http://localhost:8080/user/finishPay?outTradeNo=' + outTradeNo,
            method: 'get',
            async: false,  //是否异步请求  默认truefalse为同步请求 ，true为异步请求）
            dataType: 'JSON',
            success: function (res) {
                console.log(res);
                // res = res.data;
                if(res.status == 1){
                    window.location.href='http://localhost:8080/index';
                }else{
                    window.alert(res.message);
                }
            },
            error: function (err){
                console.log(err);
            }
        })
    })
    });
</script>
</body>
</html>